#import "ArleneLoadingMoreRow.h"


@interface ArleneLoadingMoreRow ()

@property (nonatomic, weak, readwrite) ArleneLoadingMoreCell *cell;

@end

@implementation ArleneLoadingMoreRow

- (UITableViewCell *)createCellForAutoAdjustedTableViewCell {
    ArleneLoadingMoreCell *cell = [[ArleneLoadingMoreCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[self reuseIdentifier]];
    
    self.cell = cell;
    
    return cell;
}

- (UITableViewCell *)cellForTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    ArleneLoadingMoreCell *cell = [tableView dequeueReusableCellWithIdentifier:[self reuseIdentifier]];
    
    if (cell == nil) {
        cell = (ArleneLoadingMoreCell *)[self createCellForAutoAdjustedTableViewCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    self.cell = cell;
    
    return cell;
}

- (BOOL)autoAdjustCellHeight {
    return NO;
}

- (CGFloat)cellHeight {
    return 60;
}

- (void)updateCell:(ArleneLoadingMoreCell *)cell indexPath:(NSIndexPath *)indexPath {
}

@end

@interface ArleneLoadingMoreCell ()

@property (nonatomic, strong) UIActivityIndicatorView *activityView;
@property (nonatomic, strong) UIImageView *loadingView;
@property (strong,nonatomic) CABasicAnimation *ani;

@end

@implementation ArleneLoadingMoreCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self layoutViews];
    }
    
    return self;
}

- (void)layoutViews {
    UILabel *tipsLabel = [UILabel new];
    
    [self.contentView addSubview:tipsLabel];
    
    tipsLabel.text = @"正在努力加载";
    tipsLabel.font = [UIFont boldSystemFontOfSize:12];
    tipsLabel.textColor = [UIColor colorWithRed:(90)/255.0 green:(90)/255.0 blue:(90)/255.0 alpha:1.0];
    tipsLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    tipsLabel.textAlignment = NSTextAlignmentCenter;
    tipsLabel.center =self.contentView.center;

    tipsLabel.backgroundColor = [UIColor clearColor];
    
    self.backgroundColor = [UIColor clearColor];
    
    if (_loadingView == nil) {
        UIImage *image = [UIImage imageNamed:@"lsu_feed_refresh_loading"];
        UIImageView *loadingView = [[UIImageView alloc] initWithImage:image];
        [self.contentView addSubview:_loadingView = loadingView];
    }
    
    self.loadingView.frame=CGRectMake(0, 0, 12, 12);
    self.loadingView.center = self.contentView.center;
    

    [self.loadingView.layer addAnimation:self.ani forKey:nil];
}

- (CABasicAnimation *)ani{
    if (!_ani) {
        CABasicAnimation *animate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
        animate.toValue = [NSNumber numberWithFloat:(2 * M_PI)];
        animate.duration = 1.0f;
        animate.repeatCount = 3000;
        animate.removedOnCompletion = NO;
        _ani = animate;
    }
    return _ani;
}

- (void)prepareForReuse {
    [super prepareForReuse];    
}


@end
